from Tkinter import *
from tkMessageBox import *
from svn_interface import *

class CommitUI(object):
  """
  Asks for a log message.
  """
  # TODO: generalize beyond Google Code!
  def __init__(self, master, callback):
    self.callback = callback
    self.create_toplevel_window(master, title='Commit')
    self.add_commit_ui(verb='Commit')

  def create_toplevel_window(self, master, title):
    self.master = Toplevel(master)
    self.master.title(title)

  def add_commit_ui(self, verb):
    lbl = Label(self.master, text='Type a brief message that describes the changes you made.', wraplength=300)
    lbl.pack(side=TOP, fill=X, expand=0)

    text_frame = Frame(self.master, width=400, height=300)
    text_frame.pack(side=TOP, fill=BOTH, expand=1)
    vscroll = Scrollbar(text_frame, orient=VERTICAL)
    vscroll.pack(side=RIGHT, fill=Y)
    self.text = Text(text_frame, yscrollcommand=vscroll.set, width=30, height=20)
    self.text.pack(side=TOP, fill=BOTH, expand=1)
    vscroll.config(command=self.text.yview)

    commit_button = Button(self.master, text=verb, command=self.commit)
    commit_button.pack(side=RIGHT)
    cancel_button = Button(self.master, text='Cancel', command=self.master.destroy)
    cancel_button.pack(side=LEFT)

  def commit(self):
    """Called by the UI when the Commit button is clicked."""
    self.log_message = self.text.get(1.0, END)
    self.master.destroy()
    self.callback(self.log_message)

